<template>
	<coreshop-page title="文章分类" mode="left">
		<view class="layout-notice-box">
			<view v-if="state.list.length > 0">
				<view class="item-box" v-for="item in state.list" :key="item.id"
					@click="handleRouteNavigateTo(`/pages/subpackage/article/category/category?id=${item.id}`)">
					<view class="title">{{ item.name }}</view>
				</view>
			</view>
			<view v-else class="layout-empty-box">
				<coreshop-empty :mode="EmptyEnum.data" text="暂无文章分类"></coreshop-empty>
			</view>
		</view>

	</coreshop-page>
</template>
<script setup lang="ts">
	import { reactive, onMounted } from 'vue';
	import { queryArticleClassify } from '@/core/api';
	import type { Response, ArticleClassifyType } from '@/core/models';
	import { EmptyEnum } from '@/core/enum';
	import { handleRouteNavigateTo } from '@/core/utils';

	const state = reactive<{
		list : Array<ArticleClassifyType>;
	}>({
		list: [],
	})

	onMounted(() => {
		/** 获取文档分类列表 */
		getArticleClassify()
	});

	/** 获取文档分类列表 */
	const getArticleClassify = async () => {
		uni.showLoading({
			title: "加载中..."
		})
		const articleClassify : Response<Array<ArticleClassifyType>> = await queryArticleClassify();
		if (articleClassify.data?.length > 0) {
			state.list = articleClassify.data;
		}
		uni.hideLoading();
	}
</script>
<style lang="scss" scoped>
	@import './list.scss';
</style>